package com.tengju.bff.interfaces.covercharge.entity.dto;

import com.idanchuang.component.base.util.StringUtil;
import org.apache.http.HttpStatus;

/**
 * @author liang_shi
 * @date 2020/7/13 14:49
 * @description
 */
public class HttpClientResponse {

    private String content;

    private byte[] contentByte;

    private int code;

    private String errMsg;


    /**
     * 通信状态正常
     *
     * @return
     */
    public boolean isOk() {
        return this.getCode() == HttpStatus.SC_OK || this.getCode() == HttpStatus.SC_CREATED;
    }

    /**
     * @return
     */
    public boolean isSuccess() {
        return this.getCode() != 0;
    }

    /**
     * 内容不为空
     *
     * @return
     */
    public boolean contentIsNotNull() {
        return StringUtil.isNotBlank(this.getContent());
    }

    public String getContent() {
        return content;
    }

    public HttpClientResponse setContent(String content) {
        this.content = content;
        return this;
    }

    public byte[] getContentByte() {
        return contentByte;
    }

    public HttpClientResponse setContentByte(byte[] contentByte) {
        this.contentByte = contentByte;
        return this;
    }

    public int getCode() {
        return code;
    }

    public HttpClientResponse setCode(int code) {
        this.code = code;
        return this;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public HttpClientResponse setErrMsg(String errMsg) {
        this.errMsg = errMsg;
        return this;
    }

    public String getRestContent() {
        return isOk() ? content : errMsg;
    }

    @Override
    public String toString() {
        return "HttpClientResponse{" +
                "content='" + content + '\'' +
                ", code=" + code +
                ", errMsg='" + errMsg + '\'' +
                '}';
    }
}
